package 笔试.转转;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/9/17-16:39
 * @version:1.0
 * @function: 4 3 2 3 5 2 1
 * 4
 */

public class Main03 {
    public static void main(String[] args) {
        System.out.println(findNthNumber(4, 3, 7, 10));
    }

    public static int findNthNumber(int N, int a, int b, int c) {
        // write code here
        int[] arr = new int[]{a, b, c};
        Arrays.sort(arr);
        a = arr[0];
        b = arr[1];
        c = arr[2];
        int[] k = new int[]{0, 0, 0};
        int count = 0, i = 0, temp =0;
        while (count < N) {
            if (b + b * k[1] > a + a * k[0]) {
                if (a + a * k[0] < c + c * k[2]){
                    temp = a + a * k[0];
                    k[0] += 1;
                }
                else if (a + a * k[0] == c + c * k[2]) {
                    temp = c + c * k[2];
                    k[2] += 1;
                    k[0] += 1;
                } else{
                    temp = c + c * k[2];
                    k[2] += 1;
                }
            } else if (b + b * k[1] == a + a * k[0]) {   //a=b
                if (a + a * k[0] < c + c * k[2]) {
                    temp = b + b * k[1];
                    k[1] += 1;
                    k[0] += 1;
                } else if (a + a * k[0] == c + c * k[2]) {
                    temp = c + c * k[2];
                    k[1] += 1;
                    k[0] += 1;
                    k[2] += 1;
                } else{
                    temp = c + c * k[2];
                    k[2] += 1;
                }
            } else {  //a>b
                if (b + b * k[1] < c + c * k[2]) {{
                    temp = b + b * k[1];
                    k[1] += 1;
                }
                } else if (b + b * k[1] == c + c * k[2]) {
                    temp = b + b * k[1];
                    k[1] += 1;
                    k[2] += 1;
                } else{
                    temp = c + c * k[2];
                    k[2] += 1;
                }
            }
            count++;
        }
        return temp;
    }
        public void m01 () {
            int res = 1;
            Scanner scanner = new Scanner(System.in);
            String[] s = scanner.nextLine().split(" ");
            int k = Integer.parseInt(scanner.nextLine());
            ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
            for (int i = 0; i < k; i++) {
                lists.add(new ArrayList<>());
            }
            for (int i = 0; i < s.length; i++) {
                int temp = Integer.parseInt(s[i]);
                int index = temp % k;
                ArrayList<Integer> list = lists.get(index);
                list.add(temp);
            }
            int j = 0;
            for (j = 1; j < k / 2; j++) {
                if (lists.get(j).size() == lists.get(k - j).size()) j++;
                else {
                    res = 0;
                    break;
                }
            }
            if (res == 1 && j == k / 2) res = lists.get(j).size() % 2 == 0 ? 1 : 0;
            System.out.println(res);
        }
    }
